package com.mxj.indexer.mapper;

import com.mxj.indexer.WeightDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface DatabaseMapper {
    @Insert("insert into documents (docId, title, url, content) values (#{docId}, #{title}, #{url}, #{content})")
    void insertDocument(
            @Param("docId") int docId,
            @Param("title") String title,
            @Param("url") String url,
            @Param("content") String content
    );

    @Insert("insert into weights (docId, weight) values (#{docId}, #{weight})")
    @Options(useGeneratedKeys = true, keyProperty = "wid", keyColumn = "wid")
    //wid在这里自动生成，在数据库中就不用自增了
    void insertWeight(WeightDO weightDO);

    @Insert("insert into word_to_weights (word, wid) values (#{word}, #{wid})")
    void insertWordToWeight(@Param("word") String word, @Param("wid") int wid);
}
